package com.imooc.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class FFMpegTest {

	private String ffMpeg;

	public FFMpegTest(String ffMpeg) {
		super();
		this.ffMpeg = ffMpeg;
	}

	public void convertor(String inputPath, String outPutPath) throws Exception {
		List<String> command = new ArrayList<String>();
		command.add(ffMpeg);

		command.add("-i");
		command.add(inputPath);
		command.add("-y");
		command.add(outPutPath);

		ProcessBuilder processBuilder = new ProcessBuilder(command);
		Process process = processBuilder.start();

		InputStream errorStream = process.getErrorStream();
		InputStreamReader inputStreamReader = new InputStreamReader(errorStream);
		BufferedReader br = new BufferedReader(inputStreamReader);

		String line = "";
		while ((line = br.readLine()) != null) {

		}

		if (br != null) {
			br.close();
		}
		if (inputStreamReader != null) {
			br.close();
		}
		if (errorStream != null) {
			br.close();
		}

	}

	public static void main(String[] args) throws Exception {

		FFMpegTest ffMpegTest = new FFMpegTest("C:\\ffmpeg-20160626-074fdf4-win64-static\\bin\\ffmpeg.exe");
		ffMpegTest.convertor("C:\\ffmpeg-20160626-074fdf4-win64-static\\bin\\test.MP4",
				"C:\\ffmpeg-20160626-074fdf4-win64-static\\bin\\demo.MP4");

	}

}
